<template>
  <div>
    <!-- 新增修改表单 -->
    <el-dialog 
    :title="textMap[dialogStatus]" 
    :visible.sync="DialogFormVisibleCom"
    width="90%"
    >
      <el-form ref="dataForm" :rules="rules" :model="formSubmitDataCom" label-position="right" label-width="120px"
               style="width: 98%; margin:10px auto;">
  

      <el-row :gutter="20">
        <el-col :span="8">
            <el-form-item label="所属法人" prop="lp_code">
              <el-select v-model="formSubmitDataCom.lp_code" placeholder=""
                         v-bind:disabled="true">
                <el-option v-for="item in lpOptions" :key="item.lp_code" :label="item.lp_name" :value="item.lp_code"/>
              </el-select>
            </el-form-item>

          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="拟合频率" prop="exct_fqc">
              <el-input v-model="formSubmitDataCom.exct_fqc"/>
            </el-form-item>
          </el-col> -->
          <!-- 拟合频率-分 -->
          <el-col :span="8">
            <el-form-item label="拟合频率-分">
              <el-select 
                v-model="formSubmitDataCom.exct_fqc_minute" 
                class="filter-item" 
                placeholder=""
                >
                <el-option v-for="item in exct_fqc_minute_options" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>

          <!-- 拟合频率-时 -->
          <el-col :span="8">
            <el-form-item label="拟合频率-时">
              <el-select 
                v-model="formSubmitDataCom.exct_fqc_hour" 
                class="filter-item" 
                placeholder=""
                >
                <el-option v-for="item in exct_fqc_hour_options" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>

          <!-- 拟合频率-天 -->
          <el-col :span="8">
            <el-form-item label="拟合频率-天">
              <el-select 
                v-model="formSubmitDataCom.exct_fqc_day" 
                class="filter-item" 
                placeholder=""
                >
                <el-option v-for="item in exct_fqc_day_options" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>

          <!-- 拟合频率-星期 -->
          <el-col :span="8">
            <el-form-item label="拟合频率-星期">
              <el-select 
                v-model="formSubmitDataCom.exct_fqc_week" 
                class="filter-item" 
                placeholder=""
                >
                <el-option v-for="item in exct_fqc_week_options" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>

          <!-- 拟合频率-月 -->
          <el-col :span="8">
            <el-form-item label="拟合频率-月">
              <el-select 
                v-model="formSubmitDataCom.exct_fqc_month" 
                class="filter-item" 
                placeholder=""
                >
                <el-option v-for="item in exct_fqc_month_options" :key="item.value" :label="item.label" :value="item.value"/>
              </el-select>
            </el-form-item>
          </el-col>

           <el-col :span="8">
            <!-- 生效日期 -->
            <el-form-item label="生效日期" prop="s_date">
              <el-date-picker
                v-model="formSubmitDataCom.s_date"
                type="date"
                placeholder=""
                value-format="yyyy-MM-dd"
              />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <!-- 生效日期 -->
            <el-form-item label="失效日期" prop="e_date">
              <el-date-picker
                v-model="formSubmitDataCom.e_date"
                type="date"
                placeholder=""
                value-format="yyyy-MM-dd"
              />
            </el-form-item>
          </el-col>
      </el-row>

        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="类型--待" prop="stay_type">
              <el-select
                v-model="formSubmitDataCom.stay_type"
                class="filter-item"
                placeholder="Please select"
                @change="stayTypeChange"
                v-bind:disabled="false"
              >
                <el-option v-for="item in stayTypeOptions" :key="item.code" :label="item.name"
                           :value="item.code"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="类型--叠" prop="sppst_type">
              <el-select
                v-model="formSubmitDataCom.sppst_type"
                class="filter-item"
                placeholder="Please select"
                @change="sppstTypeChange"
                v-bind:disabled="false"
              >
                <el-option v-for="item in sppstTypeOptions" :key="item.code" :label="item.name"
                           :value="item.code"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="类型--合" prop="merge_type">
              <el-select
                v-model="formSubmitDataCom.merge_type"
                class="filter-item"
                placeholder="Please select"
                @change="mergeTypeChange"
                v-bind:disabled="false"
              >
                <el-option v-for="item in mergeTypeOptions" :key="item.code" :label="item.name"
                           :value="item.code"/>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="曲线--待" prop="stay_curve_code">
              <el-select
                v-model="formSubmitDataCom.stay_curve_code"
                class="filter-item"
                placeholder="Please select"
                v-bind:disabled="false"
                @change="stayCurveCodeChange"
              >
                <el-option v-for="item in stayCurveCodeOptions" :key="item.cv_code" :label="item.cv_name"
                           :value="item.cv_code"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="曲线--叠" prop="sppst_curve_code">
              <el-select
                v-model="formSubmitDataCom.sppst_curve_code"
                class="filter-item"
                placeholder="Please select"
                v-bind:disabled="false"
                @change="sppstCurveCodeChange"
              >
                <el-option v-for="item in sppstCurveCodeOptions" :key="item.cv_code" :label="item.cv_name"
                           :value="item.cv_code"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="曲线--合" prop="merge_curve_code">
              <el-select
                v-model="formSubmitDataCom.merge_curve_code"
                class="filter-item"
                placeholder="Please select"
                v-bind:disabled="false"
                @change="mergeCurveCodeChange"
              >
                <el-option v-for="item in mergeCurveCodeOptions" :key="item.cv_code" :label="item.cv_name"
                           :value="item.cv_code"/>
              </el-select>
            </el-form-item>
          </el-col>


          <el-col :span="24">
            <!-- 备注 -->
            <el-form-item label="备注：" prop="remark">
              <el-input type="textarea" v-model="formSubmitDataCom.remark" placeholder=""></el-input>
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button @click="resetFormData">
          重置
        </el-button>
        <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
          提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// import PageHeaderLayout from '@/layouts/PageHeaderLayout'
// import ApeDrawer from '@/components/ApeDrawer'
// import { mapGetters } from 'vuex'
// const calendarTypeOptions = [
//   { key: 'lp_code', display_name: 'lp_name' },
// ]

// // arr to obj, such as { CN : "China", US : "USA" }
// const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
//   acc[cur.key] = cur.display_name
//   return acc
// }, {})

// const rc_sg_companyOptions = [
//   {key: 'Y', display_name: '年'},
//   {key: 'M', display_name: '月'},
//   {key: 'D', display_name: '日'},
// ]

// // arr to obj, such as { CN : "China", US : "USA" }
// const calendarTypeKeyValue = rc_sg_companyOptions.reduce((acc, cur) => {
//   acc[cur.key] = cur.display_name
//   return acc
// }, {})

import XEUtils from 'xe-utils'
import exctfqcoptions from '@/views/CurveManageNew/mixins/exctfqcoptions'
export default {
  name: 'submitForm',
  mixins:[exctfqcoptions],
  components: {
    //PageHeaderLayout,
  },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },
    dialogStatus: {
      type: String,
    },
    // tableColumn: {
    //     type: Array,
    //     default() {
    //         return []
    //     }
    // },
    formSubmitData: {
      type: Object,
      default: function () {
        return {
          id: undefined,
          // stay_pct_value:100,
          // sppst_pct_value:100,

        }
      }
    },
    // 法人selectData
    // baseCurveOptions: {
    //   type: Array
    // },
    // transferCurveOptions: {
    //   type: Array
    // },
    lpOptions: {
      type: Array
    },
    //类型--待
    stayTypeOptions: {
      type: Array
    },
    //类型--叠
    sppstTypeOptions: {
      type: Array
    },
    //类型--合
    mergeTypeOptions: {
      type: Array
    },

    //曲线--待
    stayCurveCodeOptions: {
      type: Array
    },
    //曲线--叠
    sppstCurveCodeOptions: {
      type: Array
    },
    //曲线--合
    mergeCurveCodeOptions: {
      type: Array
    },

    // //期限点编号--待
    // stayTermCodeOptions: {
    //   type: Array
    // },
    // //期限点编号--叠
    // sppstTermCodeOptions: {
    //   type: Array
    // },
    // //期限点编号--合
    // mergeTermCodeOptions: {
    //   type: Array
    // },
  },


  // 定义属性
  data() {
    /* 生效日期验证 */
    var validateDateRangeSdate = (rule, value, callback) => {
      if (XEUtils.isEmpty(value)) {
        callback(new Error('生效日期必填!'));
      } else if ((!XEUtils.isEmpty(this.formSubmitDataCom.e_date)) && (value > this.formSubmitDataCom.e_date)) {
        callback(new Error('生效日期必须小于失效日期!'));
      } else {
        callback();
      }
    };
    /* 失效日期验证 */
    var validateDateRangeEdate = (rule, value, callback) => {
      if (XEUtils.isEmpty(value)) {
        callback(new Error('失效日期必填!'));
      } else if ((!XEUtils.isEmpty(this.formSubmitDataCom.s_date)) && (value < this.formSubmitDataCom.s_date)) {
        callback(new Error('失效日期必须大于生效日期!'));
      } else {
        callback();
      }
    };

    return {
      textMap: {
        update: '修改',
        create: '新增'
      },
      rules: {
        s_date: [{required: true, message: '生效日期必填', trigger: 'change'}],
        e_date: [{required: true, message: '失效日期必填', trigger: 'change'}],
        stay_type: [{required: true, message: '类型-待必填', trigger: 'change'}],
        stay_curve_code: [{required: true, message: '曲线-待必填', trigger: 'change'}],
        sppst_type: [{required: true, message: '类型-叠必填', trigger: 'change'}],
        sppst_curve_code: [{required: true, message: '曲线-叠必填', trigger: 'change'}],
        merge_type: [{required: true, message: '类型-合必填', trigger: 'change'}],
        merge_curve_code: [{required: true, message: '曲线-合必填', trigger: 'change'}],
         exct_fqc: [{required: true, message: '拟合频率必填', trigger: 'change'}],
      },
      // 表单用到的值
      //  rc_sg_companyOptions,
      // statusOptions: ['published', 'draft', 'deleted'],
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
    DialogFormVisibleCom: {
      get() {
        return this.dialogFormVisible
      },
      set(val) {
        this.$emit('update:dialogFormVisible', val)
      }
    },
    formSubmitDataCom: {
      get() {
        return this.formSubmitData
      },
      set(val) {
        this.$emit('update:formSubmitData', val)
      }
    },
    // com_merge_term_code(){
    //     return this.formSubmitDataCom.stay_pct_value + this.formSubmitDataCom.sppst_pct_value
    // },
    
  },
  // 监控data中的数据变化
  watch: {
    
  },
  // 方法集合
  methods: {
    //类型--待Change
    stayTypeChange(val){
      console.log('OOOOOOOOOOOOO');
      this.$emit('stayTypeChangeEmit',val)
    },
    //类型--叠Change
    sppstTypeChange(val){
      this.$emit('sppstTypeChangeEmit',val)
    },
    //类型--合Change
    mergeTypeChange(val){
      this.$emit('mergeTypeChangeEmit',val)
    },

    //曲线--待 Change
    stayCurveCodeChange(val){
      // this.$emit('stayCurveCodeChangeEmit',val)
    },
    //曲线--叠 Change
    sppstCurveCodeChange(val){
      // this.$emit('sppstCurveCodeChangeEmit',val)
    },
    //曲线--合 Change
    mergeCurveCodeChange(val){
      // this.$emit('mergeCurveCodeChangeEmit',val)
    },


    resetFormData() {
      let exclude = []
      let replaceObj = {}
      if (this.dialogStatus === 'create') {
        exclude = [
          'lp_code',
        ]
        replaceObj = {
          lp_code: "123456", //曲线名称
        }
      }
      console.log('this.dialogStatusthis.dialogStatus', this.dialogStatus);
      if (this.dialogStatus === 'update') {
        exclude = [
        ]
      }
      this.$emit('resetFormDataEmit', {
        exclude,
        replaceObj
      })
      // this.$emit('resetFormDataEmit')
    },
    /* 基础曲线值变化触发事件 */
    // bsCvCodeChange(val) {
    //   this.$emit('bsCvCodeChangeEmit', val)
    //   console.log('ssss', val);
    // },

    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$emit('handleFromCreateDataEmit')
        }
      })
    },

    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          // this.$delete(this.formSubmitDataCom, "_XID");
          // this.$delete(this.formSubmitDataCom, "bs_cv_name");
          // this.$delete(this.formSubmitDataCom, "tf_cv_name");
          // this.$delete(this.formSubmitDataCom, "lp_name");
          // this.$delete(this.formSubmitDataCom, "rc_sg");
          // const tempData = Object.assign({}, this.formSubmitData)
          this.$emit('handleFromUpdateDataEmit')
          // tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
          // updateArticle(tempData).then(() => {
          //   const index = this.list.findIndex(v => v.id === this.temp.id)
          //   this.list.splice(index, 1, this.temp)
          //   this.dialogFormVisible = false
          //   this.$notify({
          //     title: 'Success',
          //     message: 'Update Successfully',
          //     type: 'success',
          //     duration: 2000
          //   })
          // })
        }
      })
    },

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {
  }, // 生命周期 - 创建之前
  beforeMount() {
  }, // 生命周期 - 挂载之前
  beforeUpdate() {
  }, // 生命周期 - 更新之前
  updated() {
  }, // 生命周期 - 更新之后
  beforeDestroy() {
  }, // 生命周期 - 销毁之前
  destroyed() {
  }, // 生命周期 - 销毁完成
  activated() {
  }, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='scss' scoped>

</style>